package com.insurance.controller;

import com.insurance.domain.ResponseResult;
import com.insurance.domain.entity.Notice;
import com.insurance.domain.enums.AppHttpCodeEnum;
import com.insurance.domain.vo.NoticePageVo;
import com.insurance.service.NoticeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author qcjstudy
 * @create 2023-04-28 19:15
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @PostMapping("/list")
    public ResponseResult getNoticesByPage(@RequestBody NoticePageVo noticePageVo){
        return noticeService.getNoticesByPage(noticePageVo);
    }

    @PostMapping("/add")
    public ResponseResult add(@RequestBody Notice notice){
        return noticeService.addNotice(notice);
    }

    @PutMapping("/update")
    public ResponseResult update(@RequestBody Notice notice){
        return noticeService.updateNotice(notice);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        if(noticeService.removeById(id)){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.DELETE_FAILED);
    }
}
